#include "Exp.h"
long double Exp::calcul(long double aux1)
{
    return exp(aux1);
}

long double Exp::calcul()
{
    if (!fStang)
        exit(1);

    return calcul(fStang->calcul());
}

char *Exp::derivare()
{
    char *aux1, *aux2, *aux;

    if (!fStang)
        exit(1);

    aux1 = fStang->derivare();
    aux2 = fStang->toString();
    aux = Inmultit::concatTermeni(aux1, aux2);

    delete aux1; delete aux2;

    return aux;
}

long double Exp::calculDerivata()
{
    if (!fStang)
        exit(1);

    return Inmultit::calcul(fStang->calculDerivata(), calcul());
}

char *Exp::toString()
{
    char *aux, *aux1;
    int nrP;

    if (!fStang)
        exit(1);
    aux1 = fStang->toString();

    aux = concatTermeni(aux1);
    delete aux1;

    return aux;
}

char *Exp::concatTermeni(char *aux1)
{
    char *aux;
    int nrP;

    if (!strcmp(aux, "0"))
        return cpystr("1");

    nrP = aux1[0] == '(' ? 0 : 2;
    aux = new char[strlen(aux1) + 4 + nrP];

    strcpy(aux, "exp");
    if (nrP) strcat(aux, "(");
    strcat(aux, aux1);
    if (nrP) strcat(aux, ")");

    return aux;
}
